local weifu = fk.CreateSkill {
  name = "lvshi__weifu",
}

Fk:loadTranslationTable{
  ["lvshi__weifu"] = "威服",
  [":lvshi__weifu"] = "一名其他角色的回合开始时，你可视为对其使用智【过河拆桥】，然后若中央区内没有【杀】，你失去“威服”并于回合结束后获得“仁忌”。",
  ["#lvshi__weifu-invoke"] = "你可以对%dest发动“威服”",
  ["@@weifu-turn"] = "威服失效",
  ["$lvshi__weifu1"] = "万里肃清，百姓归附。",
  ["$lvshi__weifu2"] = "大汉天威还可传承万世！",
}

local DIY = require "packages/diy_utility/diy_utility"

weifu:addAcquireEffect(function (self, player, is_start)
  player.room:addSkill("#CenterArea")
end)
-- 威服技能实现
weifu:addEffect(fk.TurnStart, {
  anim_type = "control",
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(weifu.name) and target ~= player
  end,
  on_cost = function(self, event, target, player, data)
    local room = player.room
    return room:askToSkillInvoke(player, {
      skill_name = weifu.name,
      prompt = "#lvshi__weifu-invoke::"..target.id,
    })
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    -- 视为使用智【过河拆桥】，添加extra_data.strategy属性
    room:useVirtualCard("lvshi__dismantlement", nil, player, target, weifu.name)
    -- 检查中央区是否有杀，如果没有则失去威服获得观势
    local centerCards = DIY.getCenterCards(room)
    if not table.find(centerCards, function(id) return Fk:getCardById(id).trueName == "slash" end) then
      room:handleAddLoseSkills(player, "-" .. weifu.name)
      room.logic:getCurrentEvent():findParent(GameEvent.Turn, true, Player.HistoryGame):addCleaner(function ()
        room:handleAddLoseSkills(player, "lvshi__guanshi")
      end)
    end
  end,
})

weifu:addEffect(fk.PreCardUse, {
  can_refresh = function(self, event, target, player, data)
    return player:hasSkill(weifu.name) and target == player and data.card.skillName == weifu.name
    and data.card.type == Card.TypeTrick
  end,
  on_refresh = function(self, event, target, player, data)
    data.extra_data = data.extra_data or {}
    data.extra_data.strategy = data.card.trueName.."_scheme"
  end,
})

return weifu